#pragma once

#define SOUND_SAMPLE	0
#define SOUND_STREAM	1

#include "../APIs/FMOD/inc/fmod.hpp"
#include "../APIs/FMOD/inc/fmod_errors.h"
#include "../Objects/Object.h"

#include <vector>

using namespace std;
using namespace FMOD;

struct SoundInfo
{
	Sound * sound;
	unsigned short type;
	unsigned short id;
};

struct ChannelInfo
{
	Channel * channel;
	Object * object;
};

enum Sounds
{
	TEST_MUSIC, TEST_3D_SFX
};

class SoundManager
{
public:
	SoundManager();
	~SoundManager();
	
	int Initialize(void);
	void Shutdown(void);

	void Update(void);
	void UpdateEars(void);
	void UpdateChannel(Object * object);
	void UpdateVolumes(float sfx, float music, float master);

	Channel * Play3DSound(unsigned char sound, Object * object);
	void PlaySFXSound(unsigned char sound);
	void PlayMusicSound(unsigned char sound);

	void PauseAllSounds(void);
	void ResumeAllSounds(void);

	float GetSFXVolume(void) { return sfxVolume; }
	float GetMusicVolume(void) { return musicVolume; }
	float GetMasterVolume(void) { return masterVolume; }

private:
	void Load3DSound(const char * filename);
	void LoadSFXSound(const char * filename);
	void LoadMusicSound(const char * filename);

	void LoadAllSounds(void);
	void UnloadAllSounds(void);

	void ERRCHECK(FMOD_RESULT result);

	FMOD::System *system;
	FMOD_RESULT result;
	unsigned int version;
	int numdrivers;
	FMOD_SPEAKERMODE speakermode;
	FMOD_CAPS caps;
	char name[256];

	unsigned int soundCount;

	float sfxVolume;
	float musicVolume;
	float masterVolume;

	ChannelGroup * sfxChannel;
	ChannelGroup * musicChannel;
	ChannelGroup * masterChannel;

	vector<SoundInfo> soundLibrary;
	vector<ChannelInfo> channelLibrary;
};